﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business;

namespace TimKiemDiaDiem
{
    public partial class frmTimKiem : WorkspaceUI , IfrmTimKiem
    {
        private String m_TenDichVu = "TatCa";

        public String TenDichVu
        {
            get { return m_TenDichVu; }
            set { m_TenDichVu = value;
            }
        }

        public frmTimKiem(MainFormUI MainForm):base(MainForm)
        {
            InitializeComponent();
            m_Context = "TimKiem";
            dtgKetQua.AutoGenerateColumns = false;
            lblThongBao.Text = "";

            this.m_TimKiemCtrl.FrmTimKiem = this;
        }

        public frmTimKiem(MainFormUI MainForm , String TenDichVu)
            : base(MainForm)
        {
            InitializeComponent();
            m_Context = "TimKiem";
            dtgKetQua.AutoGenerateColumns = false;
            lblThongBao.Text = "";

            this.m_TimKiemCtrl.TenDichVu = TenDichVu;
            this.m_TenDichVu = TenDichVu;

            this.m_TimKiemCtrl.FrmTimKiem = this;
        }
        public frmTimKiem()
        {
            InitializeComponent();
        }

        private void btnQuayLai_Click(object sender, EventArgs e)
        {
            m_MainForm.LoadWorkspace(new frmChonDichVu(this.m_MainForm));
        }

        public void HienThiKetQua(List<DiaDiemDTO> Ketqua)
        {
            lblThongBao.Text = "Tìm được " + Ketqua.Count + " địa điểm";
            dtgKetQua.DataSource = Ketqua;

            LoadingForm loadForm = new LoadingForm();
            loadForm.ShowDialog(this); 
        }
       

        private void TimKiemCtrl_Load(object sender, EventArgs e)
        {
            if ("TatCa" != m_TenDichVu)
            {
                lblTenDichVu.Text = m_TenDichVu;
                m_TimKiemCtrl.TenDichVu = m_TenDichVu;
                m_TimKiemCtrl.TraCuuDiaDiem();
            }
            
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            switch (lblkTimKiemNangCao.Text)
            {
                case "Tìm Kiếm Nâng Cao":
                    this.m_TimKiemCtrl.DoiLoaiTimKiem(new TimKiemNangCaoCtrl());
                    lblkTimKiemNangCao.Text = "Tìm Kiếm Đơn Giản";
                    break;
                case "Tìm Kiếm Đơn Giản":
                    this.m_TimKiemCtrl.DoiLoaiTimKiem(new TimKiemDonGianCtrl());
                    lblkTimKiemNangCao.Text = "Tìm Kiếm Nâng Cao";
                    break;
            }
        }

        private void dtgKetQua_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            this.dtgKetQua[e.ColumnIndex, e.RowIndex].Selected = false;
            this.dtgKetQua.Rows[e.RowIndex].Selected = true;
            (m_MainForm as MainForm).MapForm.DiaDiem = (dtgKetQua.DataSource as List<DiaDiemDTO>)[e.RowIndex];
        }

        private void btnHienBanDo_Click(object sender, EventArgs e)
        {
            (m_MainForm as MainForm).MapForm.ShowDialog();
        }

    }
}
